<!--_meta 作为公共模版分离出去-->
<include file="Public/_meta" />
<!--/meta 作为公共模版分离出去-->

<title>添加用户</title>
</head>
<style>
  .input-text{
    width: 300px;
  }
</style>
<body>
<article class="page-container">
	<form method="post" class="form form-horizontal" id="form-member-add" onsubmit="return false;">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>用户名：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" id="username" name="username" value="{$info['username']}">
			</div>
		</div>

	    <div class="row cl">
	      	<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>密码：</label>
      		<div class="formControls col-xs-8 col-sm-9">
	        	<input type="password" class="input-text" placeholder="" id="password" name="password" value="">
	     	</div>
	    </div>

		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">角色名称：</label>
			<div class="formControls col-xs-8 col-sm-9"> 
				<span class="select-box" style="width:180px;">
					<select class="form-control" name="role_id" id="role_list" style="width:170px;border: none;font-size: 14px;">
						<option value="0">请选择角色</option>
						<volist name="role" id="v">
							<option value="{$v['role_id']}" <if condition="$info['role_id'] eq $v['role_id']"> selected</if> >{$v['name']}</option>
						</volist>
     				</select>
				</span> 
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>状态：</label>
			<div class="formControls col-xs-8 col-sm-9 skin-minimal">
				<div class="radio-box" style="padding-left: 0px; ">
					<input name="status" type="radio" id="sex-1" <if condition='$info["status"] eq 1'> checked </if> value="1">
					<label for="sex-1">开启</label>
				</div>
				<div class="radio-box">
					<input type="radio" id="sex-2" name="status" <if condition='$info["status"] eq 0'> checked </if> value="0">
					<label for="sex-2">关闭</label>
				</div>
			</div>
		</div>

		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<input type="hidden" name="act" value="{$act}" />
				<input type="hidden" name="admin_id" value="{$info['id']}">
				<input class="btn btn-primary radius" type="submit" onclick="adsubmit()" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</article>

<!--_footer 作为公共模版分离出去-->
<include file="Public/_footer" />
<!--/_footer 作为公共模版分离出去-->

<script type="text/javascript">
	var _index;
	function adsubmit(){
		if($('input[name=username]').val() == ''){
			layer.alert('用户名不能为空！', {icon: 2});   //alert('少年，用户名不能为空！');
			return false;
		}

		if($('input[name=password]').val() == '' && '{$act}' == 'add'){
			layer.alert('密码不能为空！', {icon: 2});//alert('少年，密码不能为空！');
			return false;
		}
		if($('#role_list').val() == 0)
		{
			layer.alert('请选择角色！', {icon: 2});//alert('少年，密码不能为空！');
			return false;
		}
		var $form = $("#form-member-add").serialize();
		$.ajax({
			url: "{:U('adminHandle')}",
			data: $form,
			type: 'post',
			sendBefore: function(){
				_index = layer.load(1);
			},
			success: function(res){
				var json = JSON.parse(res);
				if(json.status != 0)
				{
					layer.alert(json.message, {icon: 2});
					return false;
				}
				else
				{
					layer.alert(json.message, {icon: 1}, function(){
						parent.location.reload(); //刷新父页面
						var index = parent.layer.getFrameIndex(window.name);
						parent.layer.close(index);
					});
				}
			},
			error: function(){
				layer.alert('网络错误，请稍后重试！', {icon: 2});
				return false;
			},
			complete: function(){
				layer.close(_index);
			}
		});
		// console.log($('#role_list').val());
	}
// $(function(){	
// 	$("#form-member-add").validate({
// 		rules:{
// 			username:{
// 				required:true,
// 				minlength:2,
// 			},
// 			status:{
// 				required:true,
// 			},
// 			mobile:{
// 				required:true,
// 				isMobile:true,
// 			},
// 			email:{
// 				required:true,
// 				email:true,
// 			},
// 			expire_time:{
// 				required:true,
// 			},
			
// 		},
// 		onkeyup:false,
// 		focusCleanup:true,
// 		success:"valid",
// 		submitHandler:function(form){
// 			$(form).ajaxSubmit({
// 		        success:function(res) {
// 		          	var data = JSON.parse(res);
// 		          	if(data.status == 1)
// 		          	{
// 			            layer.msg(data.message,{
// 			              	icon:1,
// 		            		time:2000
// 			            },function(){
// 			              	// parent.location.href=parent.location.href;
// 			              	parent.location.reload(); //刷新父页面
// 			              	var index = parent.layer.getFrameIndex(window.name);
// 			              	parent.layer.close(index);
// 			            })
// 		          	}else{
// 		            	layer.msg(data.message,{
// 			              	icon:2,
// 			              	time:2000
// 			            })
// 		          	}
// 		        }
// 		    });
// 		}
// 	});
// });



</script> 

</body>
</html>